package com.shouxin.attendance.database.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.shouxin.attendance.database.dao.BabyDao;
import com.shouxin.attendance.database.dao.ClazzDao;
import com.shouxin.attendance.database.dao.DaoSession;

import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.JoinProperty;
import org.greenrobot.greendao.annotation.NotNull;
import org.greenrobot.greendao.annotation.OrderBy;
import org.greenrobot.greendao.annotation.ToMany;

import java.util.List;

@Entity(nameInDb = "t_class")
public class Clazz {

	@Id
	@JSONField(name = "class_id")
	private Long id;

	@NotNull
	private String name;

	@NotNull
	@JSONField(name = "is_hall_night")
	private Integer nightStudy;

	@ToMany(joinProperties = {@JoinProperty(name = "id", referencedName = "classId")})
	@OrderBy("id ASC")
	private List<Baby> babyList;

	/** Used to resolve relations */
	@Generated(hash = 2040040024)
	private transient DaoSession daoSession;

	/** Used for active entity operations. */
	@Generated(hash = 909266378)
	private transient ClazzDao myDao;


	@Generated(hash = 10036165)
	public Clazz(Long id, @NotNull String name, @NotNull Integer nightStudy) {
		this.id = id;
		this.name = name;
		this.nightStudy = nightStudy;
	}

	@Generated(hash = 1166360579)
	public Clazz() {
	}


	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@NotNull
	public String getName() {
		return name;
	}

	public void setName(@NotNull String name) {
		this.name = name;
	}

	@NotNull
	public Integer getNightStudy() {
		return nightStudy;
	}

	public void setNightStudy(@NotNull Integer nightStudy) {
		this.nightStudy = nightStudy;
	}

	@Override
	public String toString() {
		return "Clazz{" +
				"id=" + id +
				", name='" + name + '\'' +
				", nightStudy=" + nightStudy +
				'}';
	}

	/**
	 * To-many relationship, resolved on first access (and after reset).
	 * Changes to to-many relations are not persisted, make changes to the target entity.
	 */
	@Generated(hash = 413139924)
	public List<Baby> getBabyList() {
					if (babyList == null) {
									final DaoSession daoSession = this.daoSession;
									if (daoSession == null) {
													throw new DaoException("Entity is detached from DAO context");
									}
									BabyDao targetDao = daoSession.getBabyDao();
									List<Baby> babyListNew = targetDao._queryClazz_BabyList(id);
									synchronized (this) {
													if (babyList == null) {
																	babyList = babyListNew;
													}
									}
					}
					return babyList;
	}

	/** Resets a to-many relationship, making the next get call to query for a fresh result. */
	@Generated(hash = 248056618)
	public synchronized void resetBabyList() {
					babyList = null;
	}

	/**
	 * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
	 * Entity must attached to an entity context.
	 */
	@Generated(hash = 128553479)
	public void delete() {
					if (myDao == null) {
									throw new DaoException("Entity is detached from DAO context");
					}
					myDao.delete(this);
	}

	/**
	 * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
	 * Entity must attached to an entity context.
	 */
	@Generated(hash = 1942392019)
	public void refresh() {
					if (myDao == null) {
									throw new DaoException("Entity is detached from DAO context");
					}
					myDao.refresh(this);
	}

	/**
	 * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
	 * Entity must attached to an entity context.
	 */
	@Generated(hash = 713229351)
	public void update() {
					if (myDao == null) {
									throw new DaoException("Entity is detached from DAO context");
					}
					myDao.update(this);
	}

	/** called by internal mechanisms, do not call yourself. */
	@Generated(hash = 2098165323)
	public void __setDaoSession(DaoSession daoSession) {
		this.daoSession = daoSession;
		myDao = daoSession != null ? daoSession.getClazzDao() : null;
	}

}
